
from itertools import combinations

def generate_combinations():
    numbers = [f"{i:02d}" for i in range(1, 11)]
    all_combos = list(combinations(numbers, 4))
    valid_combos = []
    
    # 采用最大覆盖策略
    for combo in all_combos:
        if not valid_combos:
            valid_combos.append(combo)
            continue
            
        # 检查与已有组合的重复情况
        max_overlap = max(len(set(combo) & set(existing)) for existing in valid_combos)
        if max_overlap <= 3:
            valid_combos.append(combo)
    
    return valid_combos

def save_results(combinations_list):
    with open('combinations_output.txt', 'w') as f:
        f.write(f"总组合数: {len(combinations_list)}\n\n")
        for idx, combo in enumerate(combinations_list, 1):
            f.write(f"组合{idx:03d}: {', '.join(combo)}\n")

if __name__ == "__main__":
    result = generate_combinations()
    save_results(result)
    print(f"已生成{len(result)}组有效组合")
